//
//  ButtonsViewController.m
//  DJIVideo
//
//  Created by wenpd on 2021/4/7.
//

#import "ButtonsViewController.h"
#import "ReactiveObjC.h"
#import "Pub_Defines.h"

@interface ButtonsViewController ()

@property (assign, nonatomic) BOOL isFPv;
@property (assign, nonatomic) BOOL isStarted;

@end

@implementation ButtonsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.02];
    [self initView];
    [self customInitBind];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)initView{
    NSString* fpv_key = (self.isFPv)?@"Change_To_Primary":@"Change_To_FPV";
    NSString* title = NSLocalizedStringFromTable(fpv_key, STR_TABLE, nil);
    [self.changSource setTitle:title forState:UIControlStateNormal];
    
    title = NSLocalizedStringFromTable(@"Server_Setting", STR_TABLE, nil);
    [self.settingBtn setTitle:title forState:UIControlStateNormal];
    
    NSString* start_key = (self.isStarted)?@"Stop_Send":@"Start_Send";
    title = NSLocalizedStringFromTable(start_key, STR_TABLE, nil);
    [self.startSending setTitle:title forState:UIControlStateNormal];
}

- (void)customInitBind{
    WeakRef(weakSelf);
    [[_startSending rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        weakSelf.isStarted = !weakSelf.isStarted;
        [weakSelf.delegate startSendingProcess:weakSelf.isStarted];
        [weakSelf initView];
    }];
    
    [[_changSource rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        weakSelf.isFPv = !weakSelf.isFPv;
        [weakSelf.delegate changSource:weakSelf.isFPv];
        [weakSelf initView];
    }];
    
    [[_settingBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        [weakSelf.delegate showSettingDialog];
    }];
}
@end
